<?php
/**
 * 熵巡 - 企业级氚云OpenAPI数据管理平台
 * 开发归属 Alyr.net
 * 主页面 - 系统首页及TAB导航
 * 尊重劳动成果是一种美德
 */

// 设置session目录权限
ini_set('session.save_path', sys_get_temp_dir());
session_start();

// 检查登录状态
if (!isset($_SESSION['logged_in']) || $_SESSION['logged_in'] !== true) {
    header('Location: login.php');
    exit;
}

$username = $_SESSION['username'] ?? 'admin';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>氚云API管理系统</title>
    <link rel="stylesheet" href="css/variables.css?v=<?php echo time(); ?>">
    <link rel="stylesheet" href="css/main.css?v=<?php echo time(); ?>">
    <link rel="stylesheet" href="css/data-query.css?v=<?php echo time(); ?>">
    <link rel="stylesheet" href="css/data-sync.css?v=<?php echo time(); ?>">
    <link rel="stylesheet" href="css/field-manage.css?v=<?php echo time(); ?>">
    <link rel="stylesheet" href="css/schema-manage.css?v=<?php echo time(); ?>">
    <link rel="stylesheet" href="css/api-docs.css?v=<?php echo time(); ?>">
    <link rel="stylesheet" href="database/css/database.css?v=<?php echo time(); ?>">
    <link rel="stylesheet" href="plugin/css/plugin.css?v=<?php echo time(); ?>">
    <link rel="stylesheet" href="plugin/dingtalk/css/dingtalk.css?v=<?php echo time(); ?>">
</head>
<body>
    <!-- 主页面头部 -->
    <div class="main-header">
        <div class="container">
            <div>
                <h1 class="main-title"><img src="images/logomini.png" alt="Logo" class="logo-icon">氚云API管理系统</h1>
                <div>
                    <span class="welcome-text" onclick="showUserConfigModal()">欢迎，<?php echo htmlspecialchars($username); ?> <i class="user-config-icon">⚙</i></span>
                    <button onclick="if(confirm('确定要退出登录吗？')){window.location.href='logout.php';}" class="btn btn-secondary">退出</button>
                </div>
            </div>
        </div>
    </div>
    
    <!-- TAB导航 -->
    <div class="container">
        <div class="tab-nav">
            <ul class="tab-list">
                <li class="tab-item">
                    <a href="#" class="tab-link" data-tab="basic-config">基础配置</a>
                </li>
                <li class="tab-item">
                    <a href="#" class="tab-link" data-tab="schema-manage">表单管理</a>
                </li>
                <li class="tab-item">
                    <a href="#" class="tab-link" data-tab="data-query">数据查询</a>
                </li>
                <li class="tab-item">
                    <a href="#" class="tab-link" data-tab="data-sync">数据同步</a>
                </li>
                <li class="tab-item">
                    <a href="#" class="tab-link" data-tab="field-manage">字段数据</a>
                </li>
                <li class="tab-item">
                    <a href="#" class="tab-link" data-tab="cloud-database">云数据库</a>
                </li>
                <li class="tab-item">
                    <a href="#" class="tab-link" data-tab="cloud-plugin">插件扩展</a>
                </li>
                <li class="tab-item">
                    <a href="#" class="tab-link" data-tab="dev-docs">接口文档</a>
                </li>

            </ul>
        </div>
    </div>
    
    <!-- 主内容区域 -->
    <div class="container">
        <div class="tab-content">
            <!-- 基础配置 -->
            <div id="basic-config" class="content-section">
                
                <div class="config-panel">
                    <div id="config-status" class="config-status" style="display:none;">
                        正在加载配置信息...
                    </div>
                    
                    <div id="config-form" class="config-form" style="display:none;">
                        <!-- 配置表单将由JavaScript动态加载 -->
                    </div>
                </div>
            </div>
            
            <!-- 表单管理 -->
            <div id="schema-manage" class="content-section">
                <?php include 'api/schema-manage-content.php'; ?>
            </div>
            
            <!-- 数据查询 -->
            <div id="data-query" class="content-section">
                <?php include 'api/data-query-content.php'; ?>
            </div>
            
            <!-- 数据同步 -->
            <div id="data-sync" class="content-section">
                <?php include 'api/data-sync-content.php'; ?>
            </div>
            
            <!-- 字段管理 -->
            <div id="field-manage" class="content-section">
                <?php include 'api/field-manage-content.php'; ?>
            </div>
            
            <!-- 云数据库 -->
            <div id="cloud-database" class="content-section">
                <?php include 'database/cloud-database-content.php'; ?>
            </div>
            
            <!-- 插件扩展 -->
            <div id="cloud-plugin" class="content-section">
                <?php include 'plugin/cloud-plugin-content.php'; ?>
            </div>

            <!-- 接口文档 -->
            <div id="dev-docs" class="content-section">
                <?php include 'api/api-docs-content.php'; ?>
            </div>
            
        </div>
    </div>
    
    <!-- 用户配置弹窗 -->
    <div id="userConfigModal" class="modal" style="display: none;">
        <div class="modal-content">
            <div class="modal-header">
                <h3>修改管理员账号</h3>
                <span class="close" onclick="hideUserConfigModal()">&times;</span>
            </div>
            <div class="modal-body">
                <form id="userConfigForm">
                    <div class="form-group">
                        <label for="modal-username">用户名: <span class="required">*</span></label>
                        <input type="text" id="modal-username" name="username" class="form-input" required>
                    </div>
                    
                    <div class="form-row">
                        <div class="form-group">
                            <label for="modal-password">密码: <span class="required">*</span></label>
                            <input type="password" id="modal-password" name="password" class="form-input" required>
                        </div>
                        <div class="form-group">
                            <label for="modal-confirm-password">确认密码: <span class="required">*</span></label>
                            <input type="password" id="modal-confirm-password" name="confirm_password" class="form-input" required>
                        </div>
                    </div>
                    
                    <div class="form-row">
                        <div class="form-group">
                            <label for="modal-phone">手机号码:</label>
                            <input type="tel" id="modal-phone" name="phone" class="form-input" placeholder="用于短信登录验证" maxlength="11">
                            <small class="form-help">开启短信登录后此项为必填</small>
                        </div>
                        <div class="form-group">
                            <label for="modal-dingtalk-id">钉钉号码:</label>
                            <input type="text" id="modal-dingtalk-id" name="dingtalk_id" class="form-input" placeholder="用于钉钉登录验证">
                            <small class="form-help">开启钉钉登录后此项为必填，填写钉钉 UserID 或 UnionID</small>
                        </div>
                    </div>
                    
                    <div class="form-row">
                        <div class="form-group">
                            <label for="modal-wechat-id">微信号码:</label>
                            <input type="text" id="modal-wechat-id" name="wechat_id" class="form-input" placeholder="用于微信登录验证">
                            <small class="form-help">开启微信登录后此项为必填，填写微信 OpenID</small>
                        </div>
                        <div class="form-group">
                            <label for="modal-feishu-id">飞书号码:</label>
                            <input type="text" id="modal-feishu-id" name="feishu_id" class="form-input" placeholder="用于飞书登录验证">
                            <small class="form-help">开启飞书登录后此项为必填，填写飞书 Open ID 或 Union ID</small>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" onclick="hideUserConfigModal()">取消</button>
                <button type="button" class="btn btn-primary" onclick="saveUserConfig()">保存</button>
            </div>
        </div>
    </div>
    
    <script src="js/toast.js?v=<?php echo time(); ?>"></script>
    <script src="js/tabs.js?v=<?php echo time(); ?>"></script>
    <script src="js/basic-config.js?v=<?php echo time(); ?>"></script>
    <script src="js/schema-manage.js?v=<?php echo time(); ?>"></script>
    <script src="js/auth.js?v=<?php echo time(); ?>"></script>
    <script src="js/data-query.js?v=<?php echo time(); ?>"></script>
    <script src="js/data-sync.js?v=<?php echo time(); ?>"></script>
    <script src="js/field-manage.js?v=<?php echo time(); ?>"></script>
    <script src="js/cloud-database.js?v=<?php echo time(); ?>"></script>
    <script src="js/cloud-plugin.js?v=<?php echo time(); ?>"></script>
    <script src="plugin/js/plugin.js?v=<?php echo time(); ?>"></script>
    <script src="plugin/dingtalk/js/dingtalk.js?v=<?php echo time(); ?>"></script>
    <script src="plugin/sms/js/sms.js?v=<?php echo time(); ?>"></script>
    <script src="plugin/wechat/js/wechat.js?v=<?php echo time(); ?>"></script>
    <script src="plugin/feishu/js/feishu.js?v=<?php echo time(); ?>"></script>
    <script src="js/user-config.js?v=<?php echo time(); ?>"></script>

    <!-- 底部版权信息 -->
    <footer class="main-footer">
        <div class="container">
            <p>&copy; <?php echo date('Y'); ?> Alyr.net. All rights reserved.</p>
        </div>
    </footer>

</body>
</html>